package com.ruoyi.xds.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.xds.domain.XdsShop;
import com.ruoyi.xds.service.IXdsShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商铺管理Controller
 *
 * @author ruoyi
 * @date 2025-08-28
 */
@RestController
@RequestMapping("/system/shop")
public class XdsShopController extends BaseController {
    @Autowired
    private IXdsShopService xdsShopService;

    /**
     * 查询商铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(XdsShop xdsShop) {
        startPage();
        List<XdsShop> list = xdsShopService.selectXdsShopList(xdsShop);
        return getDataTable(list);
    }

    /**
     * 导出商铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:shop:export')")
    @Log(title = "商铺管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XdsShop xdsShop) {
        List<XdsShop> list = xdsShopService.selectXdsShopList(xdsShop);
        ExcelUtil<XdsShop> util = new ExcelUtil<XdsShop>(XdsShop.class);
        util.exportExcel(response, list, "商铺管理数据");
    }

    /**
     * 获取商铺管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:shop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(xdsShopService.selectXdsShopById(id));
    }

    /**
     * 新增商铺管理
     */
    @PreAuthorize("@ss.hasPermi('system:shop:add')")
    @Log(title = "商铺管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XdsShop xdsShop) {
        return toAjax(xdsShopService.insertXdsShop(xdsShop));
    }

    /**
     * 修改商铺管理
     */
    @PreAuthorize("@ss.hasPermi('system:shop:edit')")
    @Log(title = "商铺管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XdsShop xdsShop) {
        return toAjax(xdsShopService.updateXdsShop(xdsShop));
    }

    /**
     * 删除商铺管理
     */
    @PreAuthorize("@ss.hasPermi('system:shop:remove')")
    @Log(title = "商铺管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(xdsShopService.deleteXdsShopByIds(ids));
    }

    /**
     * 假删除数据
     */
    @PreAuthorize("@ss.hasPermi('system:shop:remove')")
    @Log(title = "商铺管理", businessType = BusinessType.UPDATE)
    @PostMapping("/uDel")
    public AjaxResult updateDel(@RequestBody XdsShop xdsShop) {
        return toAjax(xdsShopService.updateXdsShopDel(xdsShop));
    }
}
